from django.db import models


class College(models.Model):
    """学院"""
    coll_id = models.AutoField(primary_key=True)
    coll_name = models.CharField(unique=True, max_length=128)

    class Meta:
        db_table = "college"


class Grade(models.Model):
    """班级"""
    grade_id = models.AutoField(primary_key=True)
    grade_name = models.CharField(unique=True, max_length=128)
    collage = models.ForeignKey(to=College, on_delete=models.PROTECT, db_column='coll_name', null=True)

    class Meta:
        db_table = "grade"


class Student(models.Model):
    """学生"""
    stu_id = models.AutoField(primary_key=True)
    stu_name = models.CharField(max_length=128)
    gender = models.BooleanField(default=True)
    stu_tel = models.CharField(unique=True, max_length=20)
    grade = models.ForeignKey(to=Grade, on_delete=models.PROTECT, db_column='grade_name', null=True)
    collage = models.ForeignKey(to=College, on_delete=models.PROTECT, db_column='coll_name', null=True)

    class Meta:
        db_table = "student"
